package cn.miwu52.homeworkerp.Util;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


import androidx.annotation.Nullable;

public class MySqlOpenHelper extends SQLiteOpenHelper {
    public MySqlOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MySqlOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version, @Nullable DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }

    @Override
    public void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        //创建用户表
        sqLiteDatabase.execSQL("create table User (id integer primary key autoincrement,username varchar(255),password varchar(255),phone varchar(11),totalInEntrepot bigint,totalOutEntrepot bigint,regtime date,logintime date,grade varchar(255))");
        //创建商品表
        sqLiteDatabase.execSQL("create table Product(id varchar(255) primary key ,name varchar(255),sumInEntrepot integer,sumOutEntrepot integer,inEntrepot integer,entrepotId integer,imageUrl varchar(255))");
        //创建仓库表
        sqLiteDatabase.execSQL("create table Entrepot(id integer primary key autoincrement,entrepotName varchar(255),productSum integer)");


    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        System.out.println("数据库更新");
        //sqLiteDatabase.execSQL("create table Product(id integer primary key autoincrement,name varchar(255),sumInEntrepot integer,sumOutEntrepot integer,InEntrepot integer,enterpot integer)");
    }
}
